import requests
import time
import ddddocr
ocr = ddddocr.DdddOcr(show_ad=False)
DEBUG = True

count = 0
while True:
	count += 1
	print(f"正在进行第{count}次破解")

	img_res = requests.get(f"https://www.gushiwen.cn/RandCode.ashx?t={int(time.time()*1000)}")

	print(img_res.cookies)

	code = ocr.classification(img_res.content)
	print(f"识别到验证码{code}")
	if DEBUG:
		with open(f"./codes/gsw_{code}.jpg", "wb") as f:
			f.write(img_res.content)

	res = requests.post("https://www.gushiwen.cn/user/login.aspx", data={
		"email": "18503800568",
		"pwd": "qikuedu123",
		"code": code
	}, cookies=img_res.cookies)

	# print(res.text)

	if "我的收藏_古诗文网" in res.text:
		print(f"登录成功")
		break
